package cn.xmu.j2ee.exp.mapper.manual;

import cn.xmu.j2ee.exp.mapper.manual.po.OrdersPo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface OrdersMapper {
    @Select({
            /*
                "`id`,`customer_id`,`shop_id`,`order_sn`,`pid`,`consignee`,`region_id`,`address`,",
                "`mobile`,`message`,`order_type`,`freight_price`,`coupon_id`,`discount_price`,",
                "`origin_price`,`presale_id`,,`rebate_num`,`confirm_time`,`shipment_sn`,",
                "`state`,`substate`,`be_deleted`,`gmt_create`,`gmt_modified`,`groupon_id`",
             */
            "select",
            "`id`,`customer_id`,`shop_id`,`order_sn`,`pid`,`consignee`,`region_id`,`address`,",
            "`mobile`,`message`,`order_type`,`freight_price`,`coupon_id`,`discount_price`,",
            "`origin_price`,`presale_id`,,`rebate_num`,`confirm_time`,`shipment_sn`,",
            "`state`,`substate`,`be_deleted`,`gmt_create`,`gmt_modified`,`groupon_id`",
            "from orders",
            "where `id` = #{orderId,jdbcType=BIGINT}"
    })
    @Results(value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "customer_id", property = "customerId", jdbcType = JdbcType.BIGINT),
            @Result(column = "shop_id", property = "shopId", jdbcType = JdbcType.BIGINT),
            @Result(column = "order_sn", property = "orderSn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pid", property = "pid", jdbcType = JdbcType.BIGINT),
            @Result(column = "consignee", property = "consignee", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region_id", property = "regionId", jdbcType = JdbcType.BIGINT),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "message", property = "message", jdbcType = JdbcType.VARCHAR),
            @Result(column = "order_type", property = "orderType", jdbcType = JdbcType.TINYINT),
            @Result(column = "freight_price", property = "freightPrice", jdbcType = JdbcType.BIGINT),
            @Result(column = "coupon_id", property = "couponId", jdbcType = JdbcType.BIGINT),
            @Result(column = "discount_id", property = "discountId", jdbcType = JdbcType.BIGINT),
            @Result(column = "origin_price", property = "originPrice", jdbcType = JdbcType.BIGINT),
            @Result(column = "presale_id", property = "presaleId", jdbcType = JdbcType.BIGINT),
            @Result(column = "groupon_id", property = "grouponId", jdbcType = JdbcType.BIGINT),
            @Result(column = "rebate_num", property = "rebateNum", jdbcType = JdbcType.BIGINT),
            @Result(column = "confirm_time", property = "confirmTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "shipment_sn", property = "shipmentSn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "state", property = "state", jdbcType = JdbcType.TINYINT),
            @Result(column = "substate", property = "substate", jdbcType = JdbcType.TINYINT),
            @Result(column = "be_deleted", property = "beDelete", jdbcType = JdbcType.TINYINT),
            @Result(column = "id",property = "orderItemList",
                    many = @Many(select = "selectOrderItemByOrderId",fetchType = FetchType.LAZY))
    })
    OrdersPo selectOrdersByOrderIdWithOrderItem(Long orderId);

    @Select({
            "select",
            "`id`,`customer_id`,`shop_id`,`order_sn`,`pid`,`consignee`,`region_id`,`address`,",
            "`mobile`,`message`,`order_type`,`freight_price`,`coupon_id`,`discount_price`,",
            "`origin_price`,`presale_id`,,`rebate_num`,`confirm_time`,`shipment_sn`,",
            "`state`,`substate`,`be_deleted`,`gmt_create`,`gmt_modified`,`groupon_id`",
            "from orders",
            "where `id` = #{orderId,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "customer_id", property = "customerId", jdbcType = JdbcType.BIGINT),
            @Result(column = "shop_id", property = "shopId", jdbcType = JdbcType.BIGINT),
            @Result(column = "order_sn", property = "orderSn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pid", property = "pid", jdbcType = JdbcType.BIGINT),
            @Result(column = "consignee", property = "consignee", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region_id", property = "regionId", jdbcType = JdbcType.BIGINT),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "message", property = "message", jdbcType = JdbcType.VARCHAR),
            @Result(column = "order_type", property = "orderType", jdbcType = JdbcType.TINYINT),
            @Result(column = "freight_price", property = "freightPrice", jdbcType = JdbcType.BIGINT),
            @Result(column = "coupon_id", property = "couponId", jdbcType = JdbcType.BIGINT),
            @Result(column = "discount_id", property = "discountId", jdbcType = JdbcType.BIGINT),
            @Result(column = "origin_price", property = "originPrice", jdbcType = JdbcType.BIGINT),
            @Result(column = "presale_id", property = "presaleId", jdbcType = JdbcType.BIGINT),
            @Result(column = "groupon_id", property = "grouponId", jdbcType = JdbcType.BIGINT),
            @Result(column = "rebate_num", property = "rebateNum", jdbcType = JdbcType.BIGINT),
            @Result(column = "confirm_time", property = "confirmTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "shipment_sn", property = "shipmentSn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "state", property = "state", jdbcType = JdbcType.TINYINT),
            @Result(column = "substate", property = "substate", jdbcType = JdbcType.TINYINT),
            @Result(column = "be_deleted", property = "beDelete", jdbcType = JdbcType.TINYINT),
    })
    OrdersPo selectOrdersByOrderId(Long orderId);
}
